<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
Zapatec Utils Overview
</title>
<link rel ="stylesheet" type="text/css" href="../../../zapatec/utils/jsdocs/stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="word2num.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onLoad="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>Zapatec Utils</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="../../../zapatec/utils/jsdocs/index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="../../../zapatec/utils/jsdocs/overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="../../../zapatec/utils/jsdocs/allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>word2num.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'word2num.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="../../../zapatec/utils/jsdocs/Zapatec/word2num.html">Zapatec.word2num</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">// $Id: word2num.js 4432 2006-09-14 07:45:55Z shacka $</span>
<span class="comment">/**
 *
 * Copyright (c) 2004-2006 by Zapatec, Inc.
 * http://www.zapatec.com
 * 1700 MLK Way, Berkeley, California,
 * 94709, U.S.A.
 * All rights reserved.
 */</span>

Zapatec.word2num=<span class="reserved">function</span>() {
<span class="reserved">this</span>.init()
}

<span class="comment">// For given money sentence convert to float</span>
<span class="comment">// example: 12 thousand 3 hundred 10 dollar 50 cent --&gt; 12310.50</span>
Zapatec.word2num.<span class="reserved">prototype</span>.val2num=<span class="reserved">function</span>(strVal, delim, arrWord2Num)
{
	var p=new Zapatec.Parse(strVal, delim)
	<span class="reserved">if</span> (p.arr.length==0)
		<span class="reserved">return</span> 0

	var num, num2, numFinal=0
	<span class="reserved">for</span> (i=0; i&lt;p.arr.length; i+=2)
	{
		num=parseFloat(p.arr[i])
    var word = <span class="literal">''</span>;
    <span class="reserved">if</span> (p.arr[i+1]) {
      word = p.arr[i+1].toLowerCase();
    }
		<span class="reserved">if</span> (typeof arrWord2Num[word] != <span class="literal">'undefined'</span>)
			num *= arrWord2Num[word]
		<span class="reserved">else</span> <span class="comment">// check if plural cents--&gt;cent</span>
		<span class="reserved">if</span> (word.charAt(word.length-1)==<span class="literal">'s'</span>)
		{
			word=word.substr(0,word.length-1)
			<span class="reserved">if</span> (typeof arrWord2Num[word] != <span class="literal">'undefined'</span>)
				num *= arrWord2Num[word]
			<span class="reserved">else</span>
				alert(<span class="literal">'new nf word:'</span> + word)
		}

		numFinal+=num
	}

	<span class="reserved">return</span> numFinal;
}

<span class="comment">// Populate Arrays</span>
Zapatec.word2num.<span class="reserved">prototype</span>.init=<span class="reserved">function</span>() {
<span class="reserved">this</span>.arrWord2Num_money=[]
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'trillion'</span>] = 1000000000000
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'billion'</span>]  = 1000000000
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'million'</span>]  = 1000000
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'thousand'</span>] = 1000
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'hundred'</span>]  = 100
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'dollar'</span>]   = 1
<span class="reserved">this</span>.arrWord2Num_money[<span class="literal">'cent'</span>]     = .01

var kb=1024
<span class="reserved">this</span>.arrWord2Num_computer=[]
<span class="reserved">this</span>.arrWord2Num_computer[<span class="literal">'gb'</span>] = kb * 1000000000
<span class="reserved">this</span>.arrWord2Num_computer[<span class="literal">'mb'</span>] = kb * 1000000
<span class="reserved">this</span>.arrWord2Num_computer[<span class="literal">'kb'</span>] = kb 

<span class="reserved">this</span>.arrWord2Num_hour=[]
<span class="reserved">this</span>.arrWord2Num_hour[<span class="literal">'week'</span>]   = 7*24
<span class="reserved">this</span>.arrWord2Num_hour[<span class="literal">'day'</span>]    = 24
<span class="reserved">this</span>.arrWord2Num_hour[<span class="literal">'hour'</span>]   = 1
}
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="../../../zapatec/utils/jsdocs/help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b>Zapatec Utils</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="../../../zapatec/utils/jsdocs/index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="../../../zapatec/utils/jsdocs/overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="../../../zapatec/utils/jsdocs/allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Thu Aug 16 12:18:39 2007</div>
</body>
</html>
